#!/usr/bin/env bash

VG=app1vg
LV=testlv
SZ=32
USER=test
ROOT=/tmpmnt_testing

if [[ "$(whoami)" != $USER ]]
then
	echo "Error: This test is designed to be run by $USER."
	exit 1
fi

o=$(whoami)
g=$(id | perl -ne '/.*\((.*?)\).*\((.*?)\).*/; print $2')

# Create a package with a 2x20Mb files in it!
t='<?xml version="1.0" standalone="yes"?>
<tp2package>
<name>test_big_pkg</name>
<version>1.0.0</version>
<description>Test package for file system growth</description>
<files>'
t="$t
	<file perms=\"755\" owner=\"$o\" group=\"$g\">file1</file>
	<file perms=\"755\" owner=\"$o\" group=\"$g\">file2</file>
</files>
</tp2package>"

if [[ -d tt ]]
then
	rm -rf tt
fi

mkdir tt 
echo "$t" >tt/test_03.xml

cd tt
dd if=/dev/zero of=file1 bs=1024k count=20
dd if=/dev/zero of=file2 bs=1024k count=20
tp2pkg --overwrite --config test_03.xml --verbose --repos /tmp || exit 1

# Make the namespace in the specifed directory

../../../bin/tp2remove_ns --namespace tt_test_02 --leave

# Create the new namespace.
../../../bin/tp2make_ns --owner $o --root $ROOT --name tt_test_02 --nosqlite || exit 1 

# Now attempt to install a 40Mb file in a 32mb file systemm...

../../../bin/tp2install --namespace tt_test_02 --pkg test_big_pkg --verbose --repos /tmp 
